package com.xiaoyu.tool.configuration.wx;

import com.xiaoyu.tool.constant.WxRouterKey;
import com.xiaoyu.tool.handles.WxHandler;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *公众号自定义消息路由配置
 */
@Slf4j
@Configuration
public class WxMpRouterConfiguration {

    @Autowired
    private WxHandler wxHandler;

    @Bean
    public WxMpMessageRouter router(WxMpService wxMpService){
        final WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);
        router.rule().msgType(WxRouterKey.EVENT).handler(wxHandler).end()
              .rule().msgType(WxConsts.KefuMsgType.TEXT).handler(wxHandler).end();
        return router;
    }


}



